<?php
/*
  [EWEISHOP] Copyright(C) 2017 Elinkint Inc.
  This is NOT a freeware, use is subject to license terms
   
  MiniProgramLogin.php 2018-05-25 16:47 cunx $
   
*/

namespace common\library\wechat\miniprogram;

use common\component\wechat\Wechat;
use common\library\wechat\WechatApi;
use yii\helpers\Json;

/**
 * 登录
 * Class MiniProgramLogin
 * @package common\library\wechat\miniprogram
 * @author cunx
 */
class MiniProgramLogin extends WechatApi
{
    public static $apiType = 'miniProgram';
    /**
     * 根据 临时登录凭证code 获取用户 session 信息
     * @param string $code  code    临时登录凭证code，只能使用一次
     * @return array|bool|void
     * @author cunx
     */
    public static function getSession(string $code){
        try{
            $result = self::getInstance()->auth->session($code);
        }catch(\Exception $result){}
        return Wechat::apiError($result);
    }
}